package org.example.statistics.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.example.statistics.domain.StatisticsSell;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import org.example.statistics.domain.StatisticsBuy;
import org.example.statistics.service.IStatisticsBuyService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 统计采购报Controller
 *
 * @author 小孟微信：xiaomengcode
 * @date 2024-05-31
 */
@Controller
@RequestMapping("/statistics/statisticsBuy")
public class StatisticsBuyController extends BaseController
{
    private String prefix = "statistics/statisticsBuy";

    @Autowired
    private IStatisticsBuyService statisticsBuyService;

    @GetMapping()
    public String statisticsBuy(StatisticsBuy buy,ModelMap mp)
    {
        mp.put("buy",buy);
        return prefix + "/statisticsBuy";
    }

    /**
     * 查询统计采购报列表
     */
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(StatisticsBuy statisticsBuy)
    {
        startPage();
        List<StatisticsBuy> list = statisticsBuyService.selectStatisticsBuyList(statisticsBuy);
        return getDataTable(list);
    }

    /**
     * 导出统计采购报列表
     */
    @RequiresPermissions("statistics:statisticsBuy:export")
    @Log(title = "统计采购报", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(StatisticsBuy statisticsBuy)
    {
        List<StatisticsBuy> list = statisticsBuyService.selectStatisticsBuyList(statisticsBuy);
        ExcelUtil<StatisticsBuy> util = new ExcelUtil<StatisticsBuy>(StatisticsBuy.class);
        return util.exportExcel(list, "统计采购报数据");
    }

    /**
     * 新增统计采购报
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存统计采购报
     */
    @RequiresPermissions("statistics:statisticsBuy:add")
    @Log(title = "统计采购报", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(StatisticsBuy statisticsBuy)
    {
        return toAjax(statisticsBuyService.insertStatisticsBuy(statisticsBuy));
    }

    /**
     * 修改统计采购报
     */
    @RequiresPermissions("statistics:statisticsBuy:edit")
    @GetMapping("/edit/{statisticsBuyId}")
    public String edit(@PathVariable("statisticsBuyId") Long statisticsBuyId, ModelMap mmap)
    {
        StatisticsBuy statisticsBuy = statisticsBuyService.selectStatisticsBuyByStatisticsBuyId(statisticsBuyId);
        mmap.put("statisticsBuy", statisticsBuy);
        return prefix + "/edit";
    }

    /**
     * 修改保存统计采购报
     */
    @RequiresPermissions("statistics:statisticsBuy:edit")
    @Log(title = "统计采购报", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(StatisticsBuy statisticsBuy)
    {
        return toAjax(statisticsBuyService.updateStatisticsBuy(statisticsBuy));
    }

    /**
     * 删除统计采购报
     */
    @RequiresPermissions("statistics:statisticsBuy:remove")
    @Log(title = "统计采购报", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(statisticsBuyService.deleteStatisticsBuyByStatisticsBuyIds(ids));
    }

    @RequestMapping( "/buy")
    @ResponseBody
    public AjaxResult buy(StatisticsBuy statisticsBuy)
    {
        List<StatisticsBuy> list = statisticsBuyService.queryStatisticsBuyByGroupByMonth(statisticsBuy);
        return AjaxResult.success(list);
    }

    @RequestMapping( "/currentMonth")
    @ResponseBody
    public AjaxResult selectStatisticsBuyByCurrentMonth(StatisticsBuy StatisticsBuy)
    {
        StatisticsBuy statisticsBuy = statisticsBuyService.selectStatisticsBuyByCurrentMonth(StatisticsBuy);
        if(statisticsBuy ==null){
            statisticsBuy=new StatisticsBuy();
        }
        return AjaxResult.success(statisticsBuy);
    }
}
